package com.openatc.agent.service;

import com.openatc.agent.model.VipRouteDevice;
import com.openatc.agent.model.VipRouteDeviceOnline;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface VipRouteDeviceDao extends JpaRepository<VipRouteDevice, Integer> {
    @Transactional
    void deleteByViprouteid(int id);

    VipRouteDevice findByViprouteidAndAgentid(int vipagentid, String agentid);

    List<VipRouteDevice> findByViprouteid(int id);

    List<VipRouteDevice> findByAgentid(String agentId);

    @Query(value = "select v.id, v.agentid , v.data, d.name, v.viprouteid,   d.geometry AS geometry_str from vip_route_device v join dev d on v.agentid = d.agentid where v.viprouteid = ?1  order by v.id",nativeQuery=true)
    List<VipRouteDevice> findByViprouteidWithGeo(int id);

}
